package com.example.controller;

import com.example.common.Result;
import com.example.entity.ZyzComment;
import com.example.service.ZyzCommentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 活动评论控制器
 */
@RestController
@RequestMapping("/api/zyzComment")
public class ZyzCommentController {
    @Autowired
    private ZyzCommentService zyzCommentService;

    /**
     * 添加评论
     */
    @PostMapping("/add")
    public Result add(@RequestBody ZyzComment zyzComment) {
        int i = zyzCommentService.add(zyzComment);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @PostMapping("/delete/batch")
    public Result deleteBatch(String ids) {
        int i = zyzCommentService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改评论
     */
    @PutMapping("/update")
    public Result update(@RequestBody ZyzComment zyzComment) {
        zyzCommentService.updateById(zyzComment);
        return Result.success();
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(ZyzComment zyzComment) {
        List<Map<String, Object>> list = zyzCommentService.selectAll(zyzComment);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(ZyzComment zyzComment,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Map<String, Object>> list = zyzCommentService.selectPage(zyzComment, pageNum, pageSize);
        return Result.success(list);
    }

}
